#include <iostream>

using namespace std;

int nextBeautifulNumber(int n) {

    for (int i = n + 1; i < INT_MAX; i++) {
        int cnt[10] = {};
        int j = i;

        while (j) {
            cnt[j % 10] += 1;
            j /= 10;
        }

        if (cnt[0] != 0) {
            continue;
        }

        bool flag = 1;

        for (int m = 1; m <= 9; m++) {
            if (cnt[m] > 0 && cnt[m] != m) {
                flag = 0;
            }
        }

        if(flag == 1){
            return i;
        }else{
            continue;
        }
    }
    return 0;
}

int main() {

    cout << nextBeautifulNumber(1) << endl;

    return 0;
}